﻿Imports System.Runtime.CompilerServices
Imports System.Collections.ObjectModel
Imports Microsoft.WindowsAzure.StorageClient

<Extension()> Public Module Extensions

    ''' <summary>
    ''' Converts a generic System.Collections.Generic.IEnumerable(Of T) to a generic System.Collections.ObjectModel.ObservableCollection(Of T)
    ''' </summary>
    ''' <typeparam name="T"></typeparam>
    ''' <param name="MyCollection"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()> Public Function ToObservableCollection(Of T)(ByVal MyCollection As IEnumerable(Of T)) As  _
                ObservableCollection(Of T)

        Try
            Dim c As New ObservableCollection(Of T)(MyCollection)

            Return c
        Catch ex As Exception
            Throw New NotSupportedException(ex.InnerException.Message)
        End Try
    End Function

    <Extension()> Public Function ToCloudBlobCollection(ByVal blobItemList As IEnumerable(Of IListBlobItem)) As IList(Of CloudBlob)
        Dim c As New List(Of CloudBlob)
        For Each element In blobItemList
            c.Add(CType(element, CloudBlob))
        Next
        Return c
    End Function

End Module